package 力扣算法练习.main1.newPart1;

public class day3 {
    //https://www.nowcoder.com/practice/5a304c109a544aef9b583dce23f5f5db?tpId=182&tqId=34613&ru=/exam/oj
    public void find4(int[] arr) {
        int length = arr.length;
        int result = findMax(arr, length);
        System.out.println(result);
    }

    private static int findMax(int[] arr, int length) {
        int temp = arr[0], result = arr[0];//temp存储临时和,result存储结果
        for (int i = 1; i < length; i++) {
            if (temp < 0) {
                temp =0;
            }
            temp += arr[i];
            if (temp > result) {
                result = temp;
            }
        }
        return result;
    }

    //https://www.nowcoder.com/practice/9d1559511b3849deaa71b576fa7009dc?tpId=122&tqId=33664&ru=/exam/oj
    public  void find5(String A,String B){

        char[] Ach= A.toCharArray();
        StringBuilder sb=new StringBuilder();
        int count=0;
        StringBuilder temp=new StringBuilder();
        //直接拼接
        sb.append(B);
        sb.append(A);
        if(findPd(sb.toString())){
            count++;
        }
        sb=new StringBuilder();
        for(int i=0;i<Ach.length;i++){
            temp.append(Ach[i]);
            sb.append(temp.toString());
            sb.append(B);
            sb.append(Ach,i+1,Ach.length-i-1);
            if(findPd(sb.toString())){
                count++;
            }
            sb=new StringBuilder();
        }
        System.out.println(count);


    }

    private  boolean findPd(String str){
        char[] ch=str.toCharArray();
        int begin=0,end=ch.length-1;
        while(begin<end){
            if(ch[begin++]!=ch[end--]){
                return false;
            }
        }
        return true;
    }


}
